/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package boundless.entities;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author hendrikdekock
 */
@Entity
@Table(name = "JOINREQUESTS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Joinrequests.findAll", query = "SELECT j FROM Joinrequests j"),
    @NamedQuery(name = "Joinrequests.findByUserid", query = "SELECT j FROM Joinrequests j WHERE j.joinrequestsPK.userid = :userid"),
    @NamedQuery(name = "Joinrequests.findByLeagueid", query = "SELECT j FROM Joinrequests j WHERE j.joinrequestsPK.leagueid = :leagueid")})
public class Joinrequests implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected JoinrequestsPK joinrequestsPK;
    @JoinColumn(name = "LEAGUEID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private League league;
    @JoinColumn(name = "USERID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Account account;

    public Joinrequests() {
    }

    public Joinrequests(JoinrequestsPK joinrequestsPK) {
        this.joinrequestsPK = joinrequestsPK;
    }

    public Joinrequests(int userid, int leagueid) {
        this.joinrequestsPK = new JoinrequestsPK(userid, leagueid);
    }

    public Joinrequests(Account account, League league) {
        this.joinrequestsPK = new JoinrequestsPK(account.getId(), league.getId());
        this.account = account;
        this.league = league;
    }
    
    public JoinrequestsPK getJoinrequestsPK() {
        return joinrequestsPK;
    }

    public void setJoinrequestsPK(JoinrequestsPK joinrequestsPK) {
        this.joinrequestsPK = joinrequestsPK;
    }

    public League getLeague() {
        return league;
    }

    public void setLeague(League league) {
        this.league = league;
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (joinrequestsPK != null ? joinrequestsPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Joinrequests)) {
            return false;
        }
        Joinrequests other = (Joinrequests) object;
        if ((this.joinrequestsPK == null && other.joinrequestsPK != null) || (this.joinrequestsPK != null && !this.joinrequestsPK.equals(other.joinrequestsPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        //return "boundless.entities.Joinrequests[ joinrequestsPK=" + joinrequestsPK + " ]";
        return joinrequestsPK.toString();
    }
    
}
